package com.example.consumer.config;

import com.rabbitmq.client.AMQP;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

@Configuration
public class RabbitConfig {
    public static final String QUEUE_NAME1 = "direct_queue_name1";
    public static final String QUEUE_NAME2 = "direct_queue_name2";
    public static final String DIRECT_EXCHANGE_NAME = "direct_exchange_name";

    @Bean
    Queue createQueue1(){
        return new Queue(QUEUE_NAME1,true,false,false);
    }

    @Bean
    Queue createQueue2(){
        return new Queue(QUEUE_NAME2,true,false,false);
    }


    //exhcange define
    @Bean
    DirectExchange createExchange(){
        //name,durable,autoDelete
        return new DirectExchange(DIRECT_EXCHANGE_NAME,true,false);
    }

    /**
     * 交换机和队列绑定起来
     * bind（create队列()） to（create交换机()）  with（routing_key/queue_name）
     */
    @Bean
    Binding directBinding1(){
        return BindingBuilder.bind(createQueue1()).to(createExchange()).with(QUEUE_NAME1);
    }

    @Bean
    Binding directBinding2(){
        return BindingBuilder.bind(createQueue2()).to(createExchange()).with(QUEUE_NAME2);
    }

}
